<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <!-- <el-form-item label="外键 用户表" prop="wgYonghu">
        <el-input
          v-model="queryParams.wgYonghu"
          placeholder="请输入外键 用户表"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item
        label="网关编号
"
        prop="wgId"
      >
        <el-input
          v-model="queryParams.wgId"
          placeholder="请输入网关编号
"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="网管名称" prop="wgName">
        <el-input
          v-model="queryParams.wgName"
          placeholder="请输入网管名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="信号道" prop="wgXinhao">
        <el-input
          v-model="queryParams.wgXinhao"
          placeholder="请输入信号道"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="网络号" prop="wgWangluo">
        <el-input
          v-model="queryParams.wgWangluo"
          placeholder="请输入网络号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="wgDizhi">
        <el-input
          v-model="queryParams.wgDizhi"
          placeholder="请输入地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="信号强度" prop="wgQiangdu">
        <el-input
          v-model="queryParams.wgQiangdu"
          placeholder="请输入信号强度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="wgBeizhu">
        <el-input
          v-model="queryParams.wgBeizhu"
          placeholder="请输入备注"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="0/1 0在线 1离线" prop="wgState">
        <el-input
          v-model="queryParams.wgState"
          placeholder="请输入0/1 0在线 1离线"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="位置" prop="wgWeizhi">
        <el-input
          v-model="queryParams.wgWeizhi"
          placeholder="请输入位置"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="0/1 0正常 1删除" prop="wgZhuangtai">
        <el-input
          v-model="queryParams.wgZhuangtai"
          placeholder="请输入0/1 0正常 1删除"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="wgCreatetime">
        <el-date-picker
          clearable
          size="small"
          v-model="queryParams.wgCreatetime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择创建时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="创建者" prop="wgCreateuser">
        <el-input
          v-model="queryParams.wgCreateuser"
          placeholder="请输入创建者"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="wgUpdatetime">
        <el-date-picker
          clearable
          size="small"
          v-model="queryParams.wgUpdatetime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择更新时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="修改者" prop="wgUpdateuser">
        <el-input
          v-model="queryParams.wgUpdateuser"
          placeholder="请输入修改者"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['mk:wggl:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mk:wggl:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['mk:wggl:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['mk:wggl:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="wgglList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="所属用户" align="center" prop="wgYonghu" />
      <el-table-column label="网关编号" align="center" prop="wgId"/>
      <el-table-column label="网管名称" align="center" prop="wgName" />
      <el-table-column label="信号道" align="center" prop="wgXinhao" />
      <el-table-column label="网络号" align="center" prop="wgWangluo" />
      <el-table-column label="地址" align="center" prop="wgDizhi" />
      <el-table-column label="信号强度" align="center" prop="wgQiangdu" />
      <el-table-column label="备注" align="center" prop="wgBeizhu"/>
         
      <el-table-column prop="wgState" label="状态" width="100" :filters="[{ text: '在线', value: '0' }, { text: '离线', value: '1' }]" :filter-method="filterTag" filter-placement="bottom-end">
      <template slot-scope="scope">
        <!-- <el-tag
          :type="scope.row.wgState=== '在线' ? 'primary' : 'success'"
          disable-transitions>{{scope.row.wgState}}</el-tag> -->
          <el-tag v-if="scope.row.wgState=='0' ">在线</el-tag>
          <el-tag v-else-if="scope.row.wgState=='1' ">离线</el-tag>
      </template>
    </el-table-column>
      <el-table-column label="位置" align="center" prop="wgWeizhi" />
      <!-- <el-table-column
        label="0/1 0正常 1删除"
        align="center"
        prop="wgZhuangtai"
      /> -->
      <el-table-column label="创建时间" align="center" prop="wgCreatetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.wgCreatetime,"{y}-{m}-{d} {h}:{i}:{s}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建者" align="center" prop="wgCreateuser" />
      <el-table-column label="更新时间" align="center" prop="wgUpdatetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.wgUpdatetime,'{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改者" align="center" prop="wgUpdateuser" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mk:wggl:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mk:wggl:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改网关管理对话框 -->
    <el-dialog :title="title" :visible.sync="openAdd" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- <el-form-item label="外键 用户表" prop="wgYonghu">
          <el-input v-model="form.wgYonghu" placeholder="请输入外键 用户表" />
        </el-form-item> -->
        <!-- <el-form-item
          label="网关编号" prop="wgId">
          <el-input v-model="form.wgId" placeholder="请输入网关编号"/>
        </el-form-item> -->
        <el-form-item label="网关名称" prop="wgName">
          <el-input v-model="form.wgName" placeholder="请输入网管名称" />
        </el-form-item>

        <!-- <el-form-item label="信号道" prop="wgXinhao">
          <el-input v-model="form.wgXinhao" placeholder="请输入信号道" />
        </el-form-item>
        <el-form-item label="网络号" prop="wgWangluo">
          <el-input v-model="form.wgWangluo" placeholder="请输入网络号" />
        </el-form-item>
        <el-form-item label="地址" prop="wgDizhi">
          <el-input v-model="form.wgDizhi" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="信号强度" prop="wgQiangdu">
          <el-input v-model="form.wgQiangdu" placeholder="请输入信号强度" />
        </el-form-item> -->
        <el-form-item label="备注" prop="wgBeizhu">
          <el-input v-model="form.wgBeizhu" placeholder="请输入备注" />
        </el-form-item>
         <!-- <el-form-item label="状态" prop="wgState">
          <el-input
            v-model="form.wgState"
            placeholder="请输入0/1 0在线 1离线"
          />
        </el-form-item>
        <el-form-item label="位置" prop="wgWeizhi">
          <el-input v-model="form.wgWeizhi" placeholder="请输入位置" />
        </el-form-item>
        <el-form-item label="0/1 0正常 1删除" prop="wgZhuangtai">
          <el-input
            v-model="form.wgZhuangtai"
            placeholder="请输入0/1 0正常 1删除"
          />
        </el-form-item>
        <el-form-item label="创建时间" prop="wgCreatetime">
          <el-date-picker
            clearable
            size="small"
            v-model="form.wgCreatetime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择创建时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建者" prop="wgCreateuser">
          <el-input v-model="form.wgCreateuser" placeholder="请输入创建者" />
        </el-form-item>
        <el-form-item label="更新时间" prop="wgUpdatetime">
          <el-date-picker
            clearable
            size="small"
            v-model="form.wgUpdatetime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择更新时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="修改者" prop="wgUpdateuser">
          <el-input v-model="form.wgUpdateuser" placeholder="请输入修改者" />
        </el-form-item> -->
      </el-form> 
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listWggl,
  getWggl,
  delWggl,
  addWggl,
  updateWggl,
  exportWggl,
} from "@/api/mk/wggl";

export default {
  name: "Wggl",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 网关管理表格数据
      wgglList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      openAdd: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        wgYonghu: null,
        wgId: null,
        wgName: null,
        wgXinhao: null,
        wgWangluo: null,
        wgDizhi: null,
        wgQiangdu: null,
        wgBeizhu: null,
        wgState: null,
        wgWeizhi: null,
        wgZhuangtai: null,
        wgCreatetime: null,
        wgCreateuser: null,
        wgUpdatetime: null,
        wgUpdateuser: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
        
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询网关管理列表 */
    getList() {
      this.loading = true;
      listWggl(this.queryParams).then((response) => {
        this.wgglList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        wgYonghu: null,
        wgId: null,
        wgName: null,
        wgXinhao: null,
        wgWangluo: null,
        wgDizhi: null,
        wgQiangdu: null,
        wgBeizhu: null,
        wgState: null,
        wgWeizhi: null,
        wgZhuangtai: null,
        wgCreatetime: null,
        wgCreateuser: null,
        wgUpdatetime: null,
        wgUpdateuser: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openAdd = true;
      this.title = "添加网关管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getWggl(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改网关管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateWggl(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWggl(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除网关管理编号为"' + ids + '"的数据项？')
        .then(function () {
          return delWggl(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal
        .confirm("是否确认导出所有网关管理数据项？")
        .then(() => {
          this.exportLoading = true;
          return exportWggl(queryParams);
        })
        .then((response) => {
          this.$download.name(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
